game_manager
{       
        spawn
        {
		remapshader "models/mapobjects/tanks_sd/jagdpanther_full"		"textures/caen_4/tank1"
		remapshader "models/mapobjects/tanks_sd/jagdpanther_additions_desert"	"textures/caen_4/tank2"
		remapshader "models/mapobjects/tanks_sd/mg42turret" 			"textures/caen_4/tank3"
		remapshader "models/mapobjects/blitz_sd/blitz_sd_body"			"textures/caen_4/blitz_body"

		remapshader "models/mapobjects/blitz_sd/blitz_sd_windows"		"textures/caen_4/blitz_window"

		remapshaderflush
		
		// Game rules
		wm_axis_respawntime	15
		wm_allied_respawntime	25
		wm_number_of_objectives 8
		wm_set_round_timelimit	30

		// Objectives
		// 1: Capture Town
                // 2: fix Tank
		// 3: Cross River
		// 4: Blow hq wall
		// 5: Steal maps
		// 6: Escape with maps
		// 7: Allied command post
		// 8: Axis command post

		// Current main objectives for each team (0=Axis, 1=Allies)
		wm_set_main_objective		1	0
		wm_set_main_objective		1	1

		wm_objective_status 1 0 0
		wm_objective_status 1 1 0
		wm_objective_status 2 0 0
		wm_objective_status 2 1 0
		wm_objective_status 3 0 0
		wm_objective_status 3 1 0
		wm_objective_status 4 0 0
		wm_objective_status 4 1 0
		wm_objective_status 5 0 0
		wm_objective_status 5 1 0
		wm_objective_status 6 0 0
		wm_objective_status 6 1 0
		wm_objective_status 7 0 0
		wm_objective_status 7 1 0
                wm_objective_status 8 0 0
		wm_objective_status 8 1 0

		wm_set_main_objective		1	0
		wm_set_main_objective		1	1

		// Stopwatch mode defending team (0=Axis, 1=Allies)
		wm_set_defending_team	1

		// Winner on expiration of round timer (0=Axis, 1=Allies)
		wm_setwinner	1

		wait 500
		setautospawn	"Town"	1
		setautospawn	"Town"	0
               

                accum 1 set 0  // maps stolen?
		accum 4 set 0 // have the Axis stolen the tank?

		// start triggered loops on/off as required (eg: command post radio sounds)
		disablespeaker allies_compost_sound
		disablespeaker axis_compost_sound
		disablespeaker allies_compost_sound_lms
		disablespeaker axis_compost_sound_lms

		wait 2000
		setstate cityflag invisible
		construct houseMG42_target
		construct bridgeMG42_target
		construct Bridge
		construct tank_construct
		setstate barrier_materials invisible
		setstate barrier_materials_clip invisible
		setstate barrier_flag invisible
	}

	

	trigger axis_move_tank
	{
		accum 4 abort_if_not_equal 0
                
                wm_objective_status 2 0 1
		wm_objective_status 2 1 2
                
                wm_set_main_objective		3	0
		wm_set_main_objective		3	1

		accum 4 set 1
		
                
	
        }


        trigger stolen_maps
	{
		accum 1 inc 1				// flag 
		trigger game_manager checkgame		// Check for end of game
	}

        trigger checkgame
	{
		accum 1 abort_if_not_equal 1
		wm_setwinner 0
		wait 400
		wm_endround
	}

}

maps
{
	spawn
	{        
	}

	trigger stolen
	{
		
		wm_objective_status 5 0 1
		wm_objective_status 5 1 2

		wm_set_main_objective 6 0
		wm_set_main_objective 6 1

		

		
	}

	trigger returned
	{
		wm_objective_status 5 0 0
		wm_objective_status 5 1 0

		wm_set_main_objective 5 0
		wm_set_main_objective 5 1

	}

	trigger captured
	{
	}
}
	

cityflag
{
	spawn
	{
		accum 0 set 1	// Who has the flag: 0-Axis, 1-Allied
	}

	trigger axis_capture	// Flag has been touched by an Axis player
	{
		accum 0 abort_if_equal 0 // do Axis own flag?

		accum 0 set 0 // Axis own the pole
                
                // *----------------------------------- vo ------------------------------------------*
                wm_removeteamvoiceannounce 0 "caen_axis_city_capture"
                wm_removeteamvoiceannounce 1 "caen_allies_city_capture"
                // *---------------------------------------------------------------------------------*

                wm_objective_status 		1 0 1
		wm_objective_status 		1 1 2
                wm_set_main_objective 2 0
		wm_set_main_objective 2 1
                alertentity city_wobj
		
	}

	trigger allied_capture	// Flag has been touched by an allied player
	{
		accum 0 abort_if_equal 1 // do Allies own flag?

		accum 0 set 1 // Allied own the flag
                
                // *----------------------------------- vo ------------------------------------------*
                wm_addteamvoiceannounce 0 "caen_axis_city_capture"
                wm_addteamvoiceannounce 1 "caen_allies_city_capture"
                // *---------------------------------------------------------------------------------*
                 
                wm_objective_status 		1 0 2
		wm_objective_status 		1 1 1
                wm_set_main_objective 1 0
		wm_set_main_objective 1 1
		alertentity city_wobj
               
	}

	

}

maps_radio // Exit point of map
{
	death
	{
		trigger game_manager stolen_maps
	}
}


// BUILD STUFF==================================================================

houseMG42
{ 
   spawn 
   { 
      wait 200 
      constructible_class 2
      trigger self startup 
       
   } 

   buildstart final 
   { 
   } 

   built final 
   {  
      setstate houseMG42_model default 
      setstate houseMG42_materials invisible 

      // Some kind of UI pop-up to alert players 
   } 

   decayed final 
   { 
      trigger self startup 
   } 

   death 
   { 
      trigger self startup 
      // Some kind of UI pop-up to alert players 
      wm_announce   "Axis team has destroyed the house mg42!" 
   } 

   trigger startup 
   {  
      setstate houseMG42_model invisible 
      setstate houseMG42_materials default 
      repairmg42 houseMG42_model
   } 
} 


bridgeMG42 
{ 
   spawn 
   { 
      wait 200 
      constructible_class 2 
      trigger self startup 
   } 

   buildstart final 
   { 
   } 

   built final 
   {  
      setstate bridgeMG42_model default 
      setstate bridgeMG42_materials invisible 

      // Some kind of UI pop-up to alert players 
   } 

   decayed final 
   { 
      trigger self startup 
   } 

   death 
   { 
      trigger self startup 
      // Some kind of UI pop-up to alert players 
      wm_announce   "Axis team has destroyed the bridge mg42!" 
   } 

   trigger startup 
   {  
      setstate bridgeMG42_model invisible 
      setstate bridgeMG42_materials default 
      repairmg42 bridgeMG42_model
   } 
} 



Bridge
{
	spawn
	{
		wait 400
                trigger self setup
		constructible_class 3

                
	}

	trigger setup
	{
		setstate bridge_materials invisible
		setstate bridge_materials_clip invisible
		setstate bridge_flag invisible


	}

	buildstart final
	{
		setstate bridge_materials default
		setstate bridge_materials_clip default
		setstate bridge_flag default


	}

	built final
	{
		setstate bridge_materials invisible
		setstate bridge_materials_clip invisible
		setstate bridge_flag invisible
                trigger tank setBridge

		trigger tank enable_stage2
             
                

                accum 7 abort_if_not_bitset 1

		
	}

	decayed final
	{
		setstate bridge_materials default
		setstate bridge_materials_clip default
		setstate bridge_flag default


		
	}

	death
	{
		setstate bridge_materials default
		setstate bridge_materials_clip default
		setstate bridge_flag default


		

		trigger tank disable_stage2
                


		wm_announce "The bridge has been damaged."
                // *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "caen_axis_bridge_damaged"

		wm_teamvoiceannounce 1 "caen_allies_bridge_damaged"
		// *---------------------------------------------------------------------------------*
                
                accum 7 abort_if_not_bitset 1

		
	}
        
        

        
}

barrier
{
	spawn
	{
		wait 400
		trigger barrier setup

		constructible_class 3
	}

	trigger setup
	{
		setstate barrier_materials default
		setstate barrier_materials_clip default
		setstate barrier_flag default


		setstate barrier_model invisible
	}

	buildstart final
	{
		setstate barrier_materials default
		setstate barrier_materials_clip default
		setstate barrier_flag default


		setstate barrier_model underconstruction
	}

	built final
	{
		setstate barrier_materials invisible
		setstate barrier_materials_clip invisible
		setstate barrier_flag invisible


		setstate barrier_model default

		trigger tank disable_stage4

		wm_announce "Tank Barrier has been constructed."
                // *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "caen_axis_tankbar_constructed"
                
                wm_removeteamvoiceannounce 1 "caen_allies_tankbar_construct"
                // *---------------------------------------------------------------------------------*
		
	}

	decayed final
	{
		setstate barrier_materials default
		setstate barrier_materials_clip default
		setstate barrier_flag default


		setstate barrier_model invisible
	}

	death
	{
		setstate barrier_materials default
		setstate barrier_materials_clip default
		setstate barrier_flag default


		setstate barrier_model invisible

		trigger tank enable_stage4

		wm_announce "Tank Barrier has been destroyed."
                // *----------------------------------- vo ------------------------------------------*
                wm_teamvoiceannounce 0 "caen_axis_tankbar_destroyed"

		wm_teamvoiceannounce 1 "caen_allies_tankbar_destroyed"
                wm_teamvoiceannounce 1 "caen_allies_tankbar_construct"
                wm_addteamvoiceannounce 1 "caen_allies_tankbar_construct"
 
		// *---------------------------------------------------------------------------------*
		
	}

	trigger remove
	{
		setstate barrier_toi invisible
		setstate barrier_materials invisible
		setstate barrier_materials_clip invisible
		setstate barrier_flag invisible
		setstate barrier_model invisible

		

		remove
	}
}



gate
{ 
   spawn 
   { 
      wait 200 
	  set
   { 
      constructible_class 1
	  health "30"
   } 
      setstate gate_materials invisible
   } 

   buildstart final 
   { 
   } 

   built final 
   {  
      setstate gate_materials invisible 

      // Some kind of UI pop-up to alert players 
      wm_announce   "Allied team has rebuilt the gate!" 
   } 

   decayed final 
   { 
      trigger self startup 
   } 

   death 
   { 
      trigger self startup 
      // Some kind of UI pop-up to alert players 
   } 

   trigger startup 
   {  
       
      setstate gate_materials default 
      
   } 
} 

allied_compost_built
{
	spawn
	{
		wait 400
		trigger allied_compost_built setup

		constructible_class 2
	}

	trigger setup
	{
		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1
		sethqstatus 1 0
	}

	buildstart final
	{
		setstate allied_compost_built_model underconstruction
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible
	}

	built final
	{
		setstate allied_compost_built_model default
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible

		trigger allied_compost_built_model enable_allied_features

		enablespeaker allies_compost_sound
	}

	decayed final
	{
		setstate allied_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default
	}

	death
	{
		setstate allied_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default

		trigger allied_compost_built_model disable_allied_features

		disablespeaker allies_compost_sound
	}
}

allied_compost_built_model
{
	spawn
	{
		wait 400
		setstate allied_compost_built_model invisible
	}

	trigger enable_allied_features
	{
		setchargetimefactor 1 soldier 0.75
		setchargetimefactor 1 lieutenant 0.75
		setchargetimefactor 1 medic 0.75
		setchargetimefactor 1 engineer 0.75
		setchargetimefactor 1 covertops 0.75
		sethqstatus 1 1

		wm_announce	"Allied Command Post constructed. Charge speed increased!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_compost_constructed_allies"

		wm_teamvoiceannounce 1 "allies_hq_compost_constructed"

		wm_removeteamvoiceannounce 1 "allies_hq_compost_construct"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 7 0 2
		wm_objective_status 7 1 1
	}

	trigger disable_allied_features
	{
		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1
		sethqstatus 1 0

		wm_announce	"Axis team has destroyed the Allied Command Post!"

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"

		wm_teamvoiceannounce 0 "axis_hq_compost_construct"

		wm_teamvoiceannounce 1 "allies_hq_compost_damaged"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 7 0 0
		wm_objective_status 7 1 0
	}
}

axis_compost_built
{
	spawn
	{
		wait 400
		trigger axis_compost_built setup

		constructible_class 2
	}

	trigger setup
	{
		setchargetimefactor 0 soldier 1
		setchargetimefactor 0 lieutenant 1
		setchargetimefactor 0 medic 1
		setchargetimefactor 0 engineer 1
		setchargetimefactor 0 covertops 1
		sethqstatus 0 0
	}

	buildstart final
	{
		setstate axis_compost_built_model underconstruction
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible
	}

	built final
	{
		setstate axis_compost_built_model default
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible

		trigger axis_compost_built_model enable_axis_features

		enablespeaker axis_compost_sound
	}

	decayed final
	{
		setstate axis_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default
	}

	death
	{
		setstate axis_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default

		trigger axis_compost_built_model disable_axis_features

		disablespeaker axis_compost_sound
	}
}

axis_compost_built_model
{
	spawn
	{
		wait 400
		setstate axis_compost_built_model invisible
	}

	trigger enable_axis_features
	{
		setchargetimefactor 0 soldier 0.75
		setchargetimefactor 0 lieutenant 0.75
		setchargetimefactor 0 medic 0.75
		setchargetimefactor 0 engineer 0.75
		setchargetimefactor 0 covertops 0.75
		sethqstatus 0 1

		wm_announce	"Axis Command Post constructed. Charge speed increased!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_compost_constructed"

		wm_teamvoiceannounce 1 "allies_hq_compost_constructed_axis"

		wm_removeteamvoiceannounce 0 "axis_hq_compost_construct"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 8 0 1
		wm_objective_status 8 1 2
	}

	trigger disable_axis_features
	{
		setchargetimefactor 0 soldier 1
		setchargetimefactor 0 lieutenant 1
		setchargetimefactor 0 medic 1
		setchargetimefactor 0 engineer 1
		setchargetimefactor 0 covertops 1
		sethqstatus 0 0

		wm_announce	"Allied team has destroyed the Axis Command Post!"

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"

		wm_teamvoiceannounce 0 "axis_hq_compost_damaged"

		wm_teamvoiceannounce 1 "allies_hq_compost_construct"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 8 0 0
		wm_objective_status 8 1 0
	}
}



// TANK STUFF==================================================================


tank_sound
{
	trigger start
	{
		trigger tank sound_start
		wait 3400
		trigger tank sound_move
	}

	trigger stop
	{
		trigger tank sound_stop
		wait 1400
		trigger tank sound_idle
	}

	trigger rebirth
	{
		trigger tank sound_rebirth
		wait 1400
		trigger tank sound_idle
	}
}

// digibob: converting truck script from goldrush over...
// ============================================================================
// accum 0, track state
// accum 1
//  - bit 0: bridge state		( 0 = not built,	1 = built		)
//  - bit 1: barrier state		( 0 = not built,	1 = built		)
//  - bit 2: spline status 		( 0 = not moving, 	1 = moving 		)
//  - bit 3: stuck check flag 	( 0 = not stuck, 	1 = stuck 		)
//  - bit 4: flag for message	( 0 = dont display, 1= display		)
//  - bit 5: blank				(									)
//  - bit 6: temp register 		(XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)
//  - bit 7: death status 		( 0 = alive, 		1 = dead		)
//  - bit 8: player check 		( 0 = players, 		1 = no players	)
//  - bit 9: visible state		( 0 = alive, 		1 = dead		)
// accum 2, blank
// accum 3, current movement loop position
// accum 4, stop counter
// accum 5, lockout ref counter
// accum 6, blank
// accum 7, blank
// ===========================================================================================
// spline points are spln2 -> spln47
// ===========================================================================================
// track events:
//  - tracks_forward
//  - tracks_stop
//  - tracks_turn_left
//  - tracks_turn_right


tank
{
	spawn
	{
		wait 400
		followspline 0 spln1 50000 length 32 wait

		trigger tank sound_idle
		trigger tank tracks_stop
	}

	// ========================================
	// sound stuff

	trigger sound_idle
	{
		stopsound
		playsound sound/vehicles/tank/tank_idle.wav looping volume 512
	}

	trigger sound_start
	{
		stopsound
		playsound sound/vehicles/tank/tank_revup.wav volume 196
	}

	trigger sound_move
	{
		stopsound
		playsound sound/vehicles/tank/tank_move.wav looping volume 512
	}

	trigger sound_stop
	{
		stopsound
		playsound sound/vehicles/tank/tank_revdown.wav volume 196
	}

	trigger sound_death
	{
		stopsound
		playsound sound/vehicles/tank/tank_stop.wav volume 256
	}

	trigger sound_rebirth
	{
		stopsound
		playsound sound/vehicles/tank/tank_start.wav volume 196
	}


		
	

	// ========================================
	// ========================================


// ===========================================================================================
// ===========================================================================================
	trigger tracks_forward
	{
		accum 0 abort_if_equal 1
		accum 0 set 1

		remapshader models/mapobjects/tanks_sd/jag_tracks_left 	models/mapobjects/tanks_sd/jag_tracks_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_tracks_right models/mapobjects/tanks_sd/jag_tracks_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_wheels_left 	models/mapobjects/tanks_sd/jag_wheels_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_wheels_right models/mapobjects/tanks_sd/jag_wheels_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_cogs_left 	models/mapobjects/tanks_sd/jag_cogs_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_cogs_right 	models/mapobjects/tanks_sd/jag_cogs_alt_forward

		remapshaderflush
	}

	trigger tracks_stop
	{
		accum 0 abort_if_equal 0
		accum 0 set 0

		remapshader models/mapobjects/tanks_sd/jag_tracks_left 	models/mapobjects/tanks_sd/jag_tracks_left
		remapshader models/mapobjects/tanks_sd/jag_tracks_right models/mapobjects/tanks_sd/jag_tracks_right
		remapshader models/mapobjects/tanks_sd/jag_wheels_left 	models/mapobjects/tanks_sd/jag_wheels_left
		remapshader models/mapobjects/tanks_sd/jag_wheels_right models/mapobjects/tanks_sd/jag_wheels_right
		remapshader models/mapobjects/tanks_sd/jag_cogs_left 	models/mapobjects/tanks_sd/jag_cogs_left
		remapshader models/mapobjects/tanks_sd/jag_cogs_right 	models/mapobjects/tanks_sd/jag_cogs_right

		remapshaderflush
	}

	trigger tracks_turn_left
	{
		accum 0 abort_if_equal 2
		accum 0 set 2

		remapshader models/mapobjects/tanks_sd/jag_tracks_left 	models/mapobjects/tanks_sd/jag_tracks_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_tracks_right models/mapobjects/tanks_sd/jag_tracks_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_wheels_left 	models/mapobjects/tanks_sd/jag_wheels_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_wheels_right models/mapobjects/tanks_sd/jag_wheels_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_cogs_left 	models/mapobjects/tanks_sd/jag_cogs_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_cogs_right 	models/mapobjects/tanks_sd/jag_cogs_alt_forward

		remapshaderflush
	}

	trigger tracks_turn_right
	{
		accum 0 abort_if_equal 3
		accum 0 set 3

		remapshader models/mapobjects/tanks_sd/jag_tracks_left 	models/mapobjects/tanks_sd/jag_tracks_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_tracks_right models/mapobjects/tanks_sd/jag_tracks_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_wheels_left 	models/mapobjects/tanks_sd/jag_wheels_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_wheels_right models/mapobjects/tanks_sd/jag_wheels_alt_backward
		remapshader models/mapobjects/tanks_sd/jag_cogs_left 	models/mapobjects/tanks_sd/jag_cogs_alt_forward
		remapshader models/mapobjects/tanks_sd/jag_cogs_right 	models/mapobjects/tanks_sd/jag_cogs_alt_backward

		remapshaderflush
	}

// ===========================================================================================
// ===========================================================================================

	trigger run_continue
	{
		accum 3 inc 1
		trigger self deathcheck
		trigger self stopcheck
		trigger self move
	}


// ===========================================================================================
// movement

	trigger move_check
	{
		trigger self stuck_check
		accum 1 abort_if_bitset 3
                
                trigger self dispatch
	}

	trigger move
	{
		trigger self move_check

		wait 500

		trigger self move
	}

	trigger dispatch
	{
		accum 3 trigger_if_equal 0 tank run_0
		accum 3 trigger_if_equal 1 tank run_1
		accum 3 trigger_if_equal 2 tank run_2
		accum 3 trigger_if_equal 3 tank run_3
		accum 3 trigger_if_equal 4 tank run_4
		accum 3 trigger_if_equal 5 tank run_5
		accum 3 trigger_if_equal 6 tank run_6
		accum 3 trigger_if_equal 7 tank run_7
		accum 3 trigger_if_equal 8 tank run_8
		accum 3 trigger_if_equal 9 tank run_9
		accum 3 trigger_if_equal 10 tank run_10
		accum 3 trigger_if_equal 11 tank run_11
		accum 3 trigger_if_equal 12 tank run_12
		accum 3 trigger_if_equal 13 tank run_13
		accum 3 trigger_if_equal 14 tank run_14
		accum 3 trigger_if_equal 15 tank run_15
		accum 3 trigger_if_equal 16 tank run_16
		accum 3 trigger_if_equal 17 tank run_17
		accum 3 trigger_if_equal 18 tank run_18
		accum 3 trigger_if_equal 19 tank run_19
		accum 3 trigger_if_equal 20 tank run_20
		accum 3 trigger_if_equal 21 tank run_21
		accum 3 trigger_if_equal 22 tank run_22
		accum 3 trigger_if_equal 23 tank run_23
		accum 3 trigger_if_equal 24 tank run_24
		accum 3 trigger_if_equal 25 tank run_25
		accum 3 trigger_if_equal 26 tank run_26
		accum 3 trigger_if_equal 27 tank run_27
		accum 3 trigger_if_equal 28 tank run_28
		accum 3 trigger_if_equal 29 tank run_29
		accum 3 trigger_if_equal 30 tank run_30
		accum 3 trigger_if_equal 31 tank run_31
		accum 3 trigger_if_equal 32 tank run_32
		accum 3 trigger_if_equal 33 tank run_33
		accum 3 trigger_if_equal 34 tank run_34
		accum 3 trigger_if_equal 35 tank run_35
		accum 3 trigger_if_equal 36 tank run_36
		accum 3 trigger_if_equal 37 tank run_37
		accum 3 trigger_if_equal 38 tank run_38
		accum 3 trigger_if_equal 39 tank run_39
		accum 3 trigger_if_equal 40 tank run_40
		
		
        }

	trigger run_0
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln2 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_1
	{
		trigger self tracks_forward
		trigger game_manager axis_move_tank

		accum 1 bitset 2
		followspline 0 spln3 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_2
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln4 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_3
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln5 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_4
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln6 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_5
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln7 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_6
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln8 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_7
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln9 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_8
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln10 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_9
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln11 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_10
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln12 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_11
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln13 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_12
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln14 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_13
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln15 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_14
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln16 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_15
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln17 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_16
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln18 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_17
	{       
                trigger self tracks_forward

		accum 1 bitset 2
                //BRIDGE//
                followspline 0 spln19 50 wait length 32
		followspline 0 spln20 50 wait length 32
                followspline 0 spln21 50 wait length 32
                followspline 0 spln22 50 wait length 32
                followspline 0 spln23 50 wait length 32
                followspline 0 spln24 50 wait length 32

		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_18
	{
		trigger self tracks_forward
                wm_objective_status 		3 0 1
		wm_objective_status 		3 1 2
                wm_set_main_objective 4 0
		wm_set_main_objective 4 1

		accum 1 bitset 2
		followspline 0 spln25 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_19
	{
		trigger self tracks_forward

		

		accum 1 bitset 2
		followspline 0 spln26 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_20
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln27 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_21
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln28 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_22
	{
		trigger self tracks_forward


		accum 1 bitset 2
		followspline 0 spln29 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_23
	{
		trigger self tracks_forward


		accum 1 bitset 2
		followspline 0 spln30 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_24
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln31 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_25
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln32 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_26
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln33 50 wait length 32
                

	        accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_27
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln34 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_28
	{
		trigger self tracks_forward
		 // **********************************
		trigger barrier remove
		// **********************************

		accum 1 bitset 2
		followspline 0 spln35 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_29
	{
		trigger self tracks_forward
		accum 1 bitset 2
		followspline 0 spln36 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_30
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln37 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_31
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln38 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_32
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln39 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_33
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln40 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_34
	{
		trigger self tracks_forward
                                     
                

		accum 1 bitset 2
		followspline 0 spln41 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_35
	{
		trigger self tracks_forward
                
		accum 1 bitset 2
		followspline 0 spln42 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

        trigger run_36
	{
		trigger self tracks_forward
                

		accum 1 bitset 2
		followspline 0 spln43 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}	

	trigger run_37
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln44 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	trigger run_38
	{
		trigger self tracks_forward
                
		accum 1 bitset 2
		followspline 0 spln45 50 wait length 32
		accum 1 bitreset 2
                
		
                trigger self run_continue
	}

	trigger run_39
	{
		trigger self tracks_forward

		accum 1 bitset 2
		followspline 0 spln46 50 wait length 32
		accum 1 bitreset 2

		trigger self run_continue
	}

	
	trigger run_40
	{
		trigger self tracks_stop
		accum 1 bitset 2
		followspline 0 spln47 50 wait length 32
		accum 1 bitreset 2

		trigger self script_lockout

		trigger self tracks_stop
		trigger tank sound_idle

		wm_objective_status 2 0 1
		wm_objective_status 2 1 2

		startanimation 45 10 15 nolerp norandom
		wait 666
		startanimation 0 1 15 nolerp norandom

		wait 900

		trigger tank_turret turn
                accum 3 inc 1
                
                
                
	}

// ===========================================================================================
// ===========================================================================================

// ===========================================================================================
// stuck checking
// digibob: since we cant return variables, just use bit 3 of accum 1 as a register... mmmm assembly...
	trigger stuck_check
	{
		accum 1 bitreset 3

		trigger self stuck_check_bridge_built
		trigger self stuck_check_barrier_built
		trigger self stuck_check_scriptlockout
		trigger self stuck_check_finished
	}

	trigger stuck_check_finished
	{
		accum 3 abort_if_less_than 41

		accum 1 bitset 3
	}

	trigger stuck_check_scriptlockout
	{
		accum 5 abort_if_equal 0

		accum 1 bitset 3
	}

	trigger stuck_check_bridge_built
	{
		accum 3 abort_if_not_equal 17

		accum 1 abort_if_not_bitset 0

		accum 1 bitset 3
	}

	trigger stuck_check_bridge_built_msg
	{
		accum 1 abort_if_not_bitset 0
                
		
	}

	trigger stuck_check_barrier_built
	{
		accum 3 abort_if_not_equal 26

		accum 1 abort_if_not_bitset 1

		accum 1 bitset 3
	}

	trigger stuck_check_barrier_built_msg
	{
		
		
	}

        

// ===========================================================================================
// stop check

	trigger stopcheck_setup
	{
		//accum 1 bitset 6			// stop if we're stuck/no-one's pushing :)

		accum 1 abort_if_bitset 8		// no one in the trigger, abort

		trigger self stuck_check		// call the stop check function
		accum 1 abort_if_bitset 3		// we're stuck so break out

		accum 1 bitreset 6			// we're free to move
	}

	trigger stopcheck
	{
		trigger self stopcheck_setup
		accum 1 abort_if_not_bitset 6

		trigger self script_lockout

		// Any just stopped moving stuff goes here
		trigger tank_sound 	stop
		trigger self tracks_stop
		startanimation 45 	10 	15 nolerp norandom
		wait 666
		startanimation 0 	1 	15 nolerp norandom
		wait 900
                
		trigger self script_lockout_stop
		
	}

// ===========================================================================================
// ===========================================================================================
// script lockouts

	trigger script_lockout
	{
		accum 5 inc 1
	}

	trigger script_lockout_stop
	{
		accum 5 inc -1
	}

// ===========================================================================================
// ===========================================================================================
// enable/disable

	trigger tank_enable
	{
		trigger self stuck_check
		accum 1 abort_if_bitset 3 	// stuck check

		accum 4 set 0				// reset stop counter
		accum 1 bitreset 8			// reset stop check

		accum 1 abort_if_bitset 2 	// already following spline
		accum 5 abort_if_not_equal 0	// are we not in a script lockout?

		accum 1 abort_if_bitset 7 	// death check

		// Any just started moving stuff goes here

		trigger self script_lockout
                trigger tank_sound start
		

		startanimation 55 10 15 nolerp norandom
		wait 666
		startanimation 5 40 15 nolerp norandom
		wait 500
		trigger self tracks_forward
                       
		trigger self script_lockout_stop
                
		trigger self move
	}

	trigger tank_disable
	{
		accum 4 inc 1				// up the stop counter
		accum 4 abort_if_less_than 4

		accum 1 bitset 8			// set stop check

		trigger self deathcheck
	}

// ===========================================================================================
// ===========================================================================================
// death / rebirth

	rebirth
	{
		accum 1 bitreset 9 // we're visibly alive
		accum 1 bitreset 7 // we're alive again

		trigger self script_lockout

		changemodel models/mapobjects/tanks_sd/jagdpanther_africa_tracks.md3

		setstate tank_smoke invisible
                // *----------------------------------- vo ------------------------------------------*
		
                wm_teamvoiceannounce 0 "caen_axis_tank_repaired"

		wm_teamvoiceannounce 1 "caen_allies_tank_repaired"

		
		// *---------------------------------------------------------------------------------*

		trigger tank_sound rebirth
		wait 500
                

		trigger self script_lockout_stop
                resetscript
	}

	death
	{
		accum 1 bitset 7
	}

	trigger deathcheck
	{
		accum 1 abort_if_not_bitset 7	// are we dead?
		accum 1 abort_if_bitset 9		// are we not already visibly dead?
		accum 1 abort_if_bitset 2		// are we not following a spline?
		accum 5 abort_if_not_equal 0	// are we not in a script lockout?

		accum 1 bitset 9				// we're now visibly dead

		trigger self deathcheck_message
		accum 1 bitset 4

		changemodel models/mapobjects/tanks_sd/jagdpanther_africa_tracks2.md3

		setstate tank_smoke default

		kill tank_construct

		trigger self sound_death
		trigger self tracks_stop

		trigger self script_lockout

		trigger self tracks_stop
		startanimation 45 10 15 nolerp norandom
		wait 666
		startanimation 0 1 15 nolerp norandom

		trigger self script_lockout_stop

		resetscript
	}

        

	trigger deathcheck_message
	{
		accum 1 abort_if_not_bitset 4

		wm_announce "The Tank has been damaged!"
                // *----------------------------------- vo ------------------------------------------*
		

		wm_teamvoiceannounce 0 "caen_axis_tank_damaged"

		wm_teamvoiceannounce 1 "caen_allies_tank_damaged"

		
		// *--------------------------------------------------------------------------------*
		
	}

	trigger startfire
	{
		startanimation 67 8 10 nolerp norandom noloop
	}

	trigger stopfire
	{
		startanimation 0 1 15 nolerp norandom
	}

	trigger enable_stage2
	{
		accum 1 bitreset 0
	}

	trigger disable_stage2
	{
		accum 1 bitset 0
	}

	trigger enable_stage4
	{
		accum 1 bitreset 1
	}

	trigger disable_stage4
	{
		accum 1 bitset 1
	}
}



tank_trigger
{
	spawn
	{
		wait 500

		attachtotag tank_shell tag_turret

		trigger tank_trigger bot_goal_loop
	}

	trigger bot_goal_loop
	{
		wait 4000	// check every 4 seconds
		trigger tank bot_active_check
		trigger tank_trigger bot_goal_loop
	}
}

tank_build
{
	spawn
	{
		wait 500

		attachtotag tank_shell tag_turret
	}
}

tank_construct
{
	spawn
	{
		wait 1000

		kill tank

		constructible_class 2
		constructible_health 1200
		constructible_constructxpbonus 10
		constructible_destructxpbonus 10
	}

	built final
	{
		alertentity tank

	}
}

tank_shell
{
	spawn
	{
		wait 400
		attachtotag tank tag_tank
	}
}

tank_turret
{
	spawn
	{
		wait 500

		attachtotag tank_shell tag_turret
	}

	trigger turn
	{
		wait 1000

		playsound sound/vehicles/tank/turret_spin.wav looping
		faceangles 0 340 0 3000
		stopsound
		playsound sound/vehicles/tank/turret_end.wav

		wait 500

		trigger tank startfire
		playsound sound/vehicles/tank/tank_fire.wav
		trigger boomtrigger boom_all		// triggers the hurts around explosions (each has its own wait for timing)
		trigger tank_flash run
	}

	trigger blow_wall
	{
		setstate tank_flash invisible

		wait 200
		trigger tank stopfire

		alertentity wall

		wm_objective_status 4 0 1
		wm_objective_status 4 1 2

		wm_set_main_objective		5	0
		wm_set_main_objective		5	1

		wait 100
		

		playsound sound/vehicles/tank/turret_spin.wav looping
		faceangles 0 0 0 3000
		stopsound
		playsound sound/vehicles/tank/turret_end.wav
		trigger tank sound_death
		trigger tank script_lockout_stop
                trigger antenna crash
                
                
	}
}

antenna
{
        spawn
        {
                wait 200
                faceangles 0 0 0 100
        }

        trigger crash
        {
                playsound sound/world/metalbreak.wav
                faceangles 0 0 -90 2000
                alertentity brick
                playsound sound/maps/expl_med.wav
        }
}

tank_flash
{
	spawn
	{
		setstate tank_flash invisible
	}

	trigger run
	{
		setstate tank_flash default
 		attachtotag tank_turret tag_flash
		faceangles 0 90 0 50

		wait 50

		trigger tank_turret blow_wall
	}
}

tank_disabler
{
	trigger run
	{
		trigger tank tank_disable
	}
}

tank_enabler
{
	trigger run
	{
		trigger tank tank_enable
	}
}

tank_smoke
{
	spawn
	{
		wait 300
		attachtotag tank_shell tag_smoke
		setstate tank_smoke invisible
	}
}



// these cause timed damage from the tank barrel to the wall explosion
boomtrigger
{
	trigger boom_all		// this is called from the tank to trigger all hurts
	{
		trigger hurt_barrelblast1 boom
		trigger hurt_barrelblast2 boom
		trigger hurt_wallblast boom
		wait 200
		setstate wall_toi invisible
		
                
	}
}


hurt_barrelblast1
{
	spawn
	{
		wait 200
		setstate hurt_barrelblast1 invisible
	}

	trigger boom
	{
		setstate hurt_barrelblast1 default
		wait 100
		remove
	}
}

hurt_barrelblast2
{
	spawn
	{
		wait 200
		setstate hurt_barrelblast2 invisible
	}

	trigger boom
	{
		wait 165
		setstate hurt_barrelblast2 default
		wait 100
		remove
	}
}


hurt_wallblast
{
	spawn
	{
		wait 200
		setstate hurt_wallblast invisible

		setstate hurt_barrelblast2 invisible
	}

	trigger boom
	{
		wait 200
		setstate hurt_wallblast default
		wait 100
		remove
	}
}

